<?php
/**
 * Defines patterns class for lexer.
 *
 * @package    blocks
 * @copyright &copy; 2011 Sergey Pashaev, Volgograd State Technical University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License
 */

/**
 * Class for lexer patterns.
 *
 * Class for storing patterns.
 *
 * @copyright  &copy; 2011 Sergey Pashaev, Volgograd State Technical University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License
 */
class block_formal_langs_lexer_pattern {

    /**
     * Pattern number.
     * @var int
     */
    private $number;
    
    /**
     * Pattern name.
     * @var string
     */
    private $name;

    /**
     * Pattern regexp.
     * @var string
     */
    private $regexp;

    /**
     * Active condition. If lexer current condition == $activecondition then this
     * pattern can be used. Initial value: "INITIAL".
     * @var string
     */
    private $activecondition;

    /**
     * Next condition. Condition in which lexer will get after using this
     * pattern.
     * @var string
     */
    private $nextcondition;

    /**
     * Pattern actions.
     * @var string
     */
    private $actions;

    /**
     * Basic pattern constructor.
     *
     * @param string $name - pattern name
     * @param string $regexp - pattern regexp
     * @param string $activecondition - active condition
     * @param string $nextcondition - next condition
     */
    public function __construct($number,
                                $name,
                                $regexp,
                                $actions,
                                $activecondition = 'INITIAL',
                                $nextcondition = null) {
        $this->name = $name;
        $this->regexp = $regexp;
        $this->number = $number;
        $this->activecondition = $activecondition;
        $this->nextcondition = $nextcondition;
        $this->actions = $actions;
    }

    public function actions() {
        return $this->actions;
    }

    public function name() {
        return $this->name;
    }

    public function number() {
        return $this->number;
    }

    public function activecondition() {
        return $this->activecondition;
    }

    public function nextcondition(){
        return $this->nextcondition;
    }

    public function regexp(){
        return $this->regexp;
    }
}

class block_formal_langs_lexer_action {
    private $type;
    private $errorstr;

    public function __construct($type, $errorstr = null) {
        $this->type = $type;
        $this->errorstr = $errorstr;
    }

    public function type() {
        return $this->type;
    }

    public function error_msg() {
        return $this->errorstr;
    }
}

?>
